import request from '@/utils/request'

export function getProduct(msg) {
	let query = new FormData();
	query.append('productClass', msg.productClass);
	query.append('publishStatus', msg.publishStatus);
	query.append('pageNum', msg.pageNum);
	query.append('pageSize', msg.pageSize);
	if (msg.keyword != undefined) {
		query.append('keyword', msg.keyword);
	}
	if (msg.productCategoryId != undefined) {
		query.append('productCategoryId', msg.productCategoryId);
	}
	if (msg.brandId != undefined) {
		query.append('brandId', msg.brandId);
	}
	if (msg.homeRecommendStatus != undefined) {
		query.append('homeRecommendStatus', msg.homeRecommendStatus);
	}
	if (msg.startTime != undefined) {
		query.append('startTime', msg.startTime);
		query.append('endTime', msg.endTime);
	}
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/product/list",
		method: "POST",
		data: query
	})
}

export function getAllProduct(query) {
	// let query = new FormData();
	// query.append('productClass', msg.productClass);
	// query.append('publishStatus', msg.publishStatus);
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/product/listForInput",
		method: "GET",
		params: query
	})
}

export function createProduct(query) {
	return request({
		headers: {
			"Content-type": "application/json"
		},
		url: "/product/create",
		method: "POST",
		data: query
	})
}

export function createService(query) {
	return request({
		url: "/product/create/service",
		method: "POST",
		data: query
	})
}

export function createAdvertise(query) {
	return request({
		url: "/product/create/advertise",
		method: "POST",
		data: query
	})
}


export function updateProductInfo(id) {
	return request({
		url: `/product/updateInfo/${id}`,
		method: "GET"
	})
}

export function updateProduct(id, query) {
	return request({
		url: `/product/update/${id}`,
		method: "POST",
		data: query
	})
}

export function updateServiceInfo(id) {
	return request({
		url: `/product/info/service/${id}`,
		method: "GET"
	})
}

export function updateService(id, query) {
	return request({
		url: `/product/update/service/${id}`,
		method: "POST",
		data: query
	})
}

export function updateAdverticeInfo(id) {
	return request({
		url: `/product/info/advertise/${id}`,
		method: "GET"
	})
}

export function updateAdvertice(id, query) {
	return request({
		url: `/product/update/advertise/${id}`,
		method: "POST",
		data: query
	})
}

export function updatePublish(id, status) {
	const query = new FormData();
	let ids = id.toString();
	query.append("ids", ids);
	query.append("publishStatus", status);
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/product/update/publishStatus",
		method: "POST",
		data: query
	})
}

export function updateDelete(id) {
	const query = new FormData();
	let ids = id.toString();
	query.append("ids", ids);
	query.append("deleteStatus", "1");
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/product/update/deleteStatus",
		method: "POST",
		data: query
	})
}


export function updateRecommend(id, status) {
	const query = new FormData();
	let ids = id.toString();
	query.append("ids", ids);
	query.append("recommendStatus", status);
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/product/update/recommendStatus",
		method: "POST",
		data: query
	})
}

export function searchPhone(phone) {
	let query = {
		phone: phone
	};
	return request({
		url: "/member/query/list",
		method: "POST",
		params: query
	})
}
